package  
{
	
	import flash.display.InteractiveObject;
	import net.flashpunk.graphics.Spritemap;
	import net.flashpunk.Sfx;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	/**
	 * ...
	 * @author Donatello
	 */
	public class PlayerTank extends Tank
	{
		
		[Embed(source = "img/tankSheet.png" )] private const PLAYER_ANIM:Class;
		private var playerAnim:Spritemap;	

		private var pressed:Boolean = false;
		private var cellWidth:Number = 52;
		private var cellHeight:Number = 52;
		public var ammo:int = 50;
		public var bombMode:Boolean = false;
		
		
		public function PlayerTank(px:Number,py:Number) 
		{
			playerAnim = new Spritemap(PLAYER_ANIM, cellWidth,cellHeight);
			playerAnim.add("idleUp", [0], 10, false);
			playerAnim.add("idleDown", [2], 10, false);
			playerAnim.add("idleLeft", [4], 10, false);
			playerAnim.add("idleRight", [6], 10, false);
			
			playerAnim.add("up", [0,1], 10, true);
			playerAnim.add("down", [2,3], 10, true);
			playerAnim.add("left", [4, 5], 10, true);
			playerAnim.add("right", [6, 7], 10, true);
			
			
			graphic = playerAnim;
		
			
			playerAnim.play("idleUp");
			
			
			setHitbox(cellWidth,cellHeight);
			
			super(px, py);
					
		}
		
		
		override public function update():void
		{
			if (collide("Wall", x, y))
			{
				colisiona = true;
			}
			else
				colisiona = false;
			
			
			if(!bombMode)	
			{	
				if (Input.check(Key.UP) )
				{
					move(0, -1);
					playerAnim.play("up")
				}
				else if(Input.check(Key.DOWN) )
				{
					move(0, 1);
					playerAnim.play("down")
				}
				else if(Input.check(Key.LEFT) )
				{
					move(-1, 0);
					playerAnim.play("left")
				}
				else if(Input.check(Key.RIGHT) )
				{
					move(1, 0);
					playerAnim.play("right")
				}
				else
				{	
					if (axisX == -1)  playerAnim.play("idleLeft");
					if (axisX == 1)  playerAnim.play("idleRight");
					if (axisY == -1) playerAnim.play("idleUp");
					if (axisY == 1) playerAnim.play("idleDown");
					
					
					if(ammo>0)
						checkShoot();
						
			}
			}
			

		}
		
		
		private function checkShoot():void
		{
			if (Input.check(Key.SPACE))
			{	if (!pressed)
				{	
					shoot();
					pressed = true;
					ammo -= 1;
				}
			}
			else
				pressed = false;
		}
		
		
	}

}